home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / cditp21.zip / CODEIT.E_ / DEMOMW.BAS < prev    next >
BASIC Source File  |  1992-05-27  |  13KB  |  436 lines

  1. '::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  2. '
  3. 'This module demonstrates how to use the windows from CIWIND1.LIB with the
  4. 'pull down menus from CIMENU1.LIB in version 2.1 & up of the CODE-IT toolbox.
  5. 'The main improvement in this version is the ability to call the pull down
  6. 'menus directly from a data window with either the ALT keypress or a mouse
  7. 'click on the pull down menu bar(row 1, column 1 to 80).
  8. '
  9. 'The program starts by defining the menus and windows. Then turns on the
  10. 'pull down menu bar making it visable to the user. Control of the program
  11. 'is then passed to the WindowControl SUB which determins which window to
  12. 'go to.
  13. '
  14. 'Once in a window, the user can type in data or at any time call the pull
  15. 'down menus. Pressing escape from the menu returns the user to the field
  16. 'where they came from. Selecting another window other than the one they are
  17. 'in sets the WhichWindow variable switch and causes an exit from the
  18. 'current window back to the WindowControl SUB and on to the next window.
  19. '
  20. 'Enjoy,
  21. '
  22. '       Clear Software
  23. '
  24. '::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  25.  
  26. DECLARE SUB InvoiceWindow ()
  27. DECLARE SUB MenuControl ()
  28. DECLARE SUB NameAddrsWindow ()
  29. DECLARE SUB WindowControl ()
  30. DECLARE SUB DemoMenuInit ()
  31. DECLARE SUB DemoWindowInit ()
  32.  
  33. '::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  34. 'DEMOMW.BAS Copyright (C) 1991-1992, Clear Software. ALL RIGHTS RESERVED.
  35. '::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  36.  
  37. '$INCLUDE: 'CITOOLS.BI'
  38. '$INCLUDE: 'CIMOUSE.BI'
  39. '$INCLUDE: 'CIMENU1.BI'
  40. '$INCLUDE: 'CIWIND1.BI'
  41.  
  42. '::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  43.  
  44. DEFINT A-Z
  45.  
  46. '::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  47.  
  48. CONST TRUE = -1, FALSE = 0
  49.  
  50. '::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  51.  
  52. TYPE MiscData
  53.      names      AS STRING * 35
  54.      address    AS STRING * 35
  55.      city       AS STRING * 20
  56.      state      AS STRING * 2
  57.      zip        AS STRING * 5
  58.      product    AS STRING * 35
  59.      price      AS STRING * 10
  60. END TYPE
  61.  
  62. DIM SHARED dat AS MiscData
  63.  
  64. '::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  65.  
  66. DIM SHARED DONEFLAG             'TRUE if exit was chosen from the menu
  67. DIM SHARED WhichWindow          'Control switch for window swaping
  68.  
  69. '::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  70.  
  71. '-------Initialize the data type with null strings.
  72.  
  73. dat.names = ""
  74. dat.address = ""
  75. dat.city = ""
  76. dat.state = ""
  77. dat.zip = ""
  78. dat.product = ""
  79. dat.price = ""
  80.           
  81. '-------Initialize the mouse and make sure it's off when we paint the screen.
  82.  
  83. MouseInit
  84. MouseHide
  85.  
  86. CLS
  87. COLOR 3, 0
  88. ScreenPaint 2, 79, 3, 21, "▒"
  89. DrawBox 1, 80, 2, 22, 1
  90.  
  91. '-------Initialize and run the program
  92.  
  93.  DemoMenuInit
  94.  DemoWindowInit
  95.  PullDownTitleOn
  96.  MouseShow
  97.  WindowControl
  98.  
  99. '-------Turn the couse off and restore the screen before exiting.
  100.  
  101. MouseHide
  102. COLOR 7, 0
  103. CLS
  104. END
  105.  
  106. SUB DemoMenuInit
  107.  
  108. '::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  109. 'Initialize the demo pull down menus.
  110. '
  111. 'Dimention the arrays for the pull down menu descriptions. Notice the
  112. 'dimentions are (1 TO 20).
  113. '::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  114.  
  115.     DIM pdmw1$(1 TO 20)
  116.     DIM pdmw2$(1 TO 20)
  117.  
  118. '::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  119. 'Set the menu definitions.
  120. '::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  121.  
  122.     PullDownDefine 1, 0, 1, "Window", 1
  123.     PullDownDefine 1, 1, 1, "Make Name/Address Window Active", 6
  124.     PullDownDefine 1, 2, 1, "Make Invoice Window Active", 6
  125.  
  126.     PullDownDefine 2, 0, 1, "Quit", 1
  127.     PullDownDefine 2, 1, 1, "Exit", 2
  128.  
  129.     PullDownColors 0, 7, 0, 7, 0, 7, 14, 0, 8, 7, 11, 15
  130.  
  131.  
  132. '::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  133. 'Set the area, colors and contents for the menu descriptions.
  134. '::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  135.  
  136.     PullDownTitleDescript "<Enter=Accept>  <Arrow=Next Title>  <Escape=Exit>"
  137.     PullDownDescriptArea 23, 2, 78, 11, 0
  138.  
  139.     pdmw1$(1) = " Type information into the Name/Address window"
  140.     pdmw1$(2) = " Enter a customer invoice"
  141.  
  142.     PullDownDescript 1, pdmw1$()
  143.  
  144.     pdmw2$(1) = " Exit this nifty demonstration program!"
  145.  
  146.     PullDownDescript 2, pdmw2$()
  147.  
  148. END SUB
  149.  
  150. SUB DemoWindowInit
  151.  
  152. '::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  153. 'Initialize the demo windows.
  154. '::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  155.  
  156. '------Window 1
  157.  
  158.     WindowDefine 1, 9, 71, 6, 10, "NAMES AND ADDRESSES", 1, 2
  159.    
  160.  
  161. '------Window 2
  162.  
  163.     WindowDefine 2, 15, 65, 6, 10, "INVOICE", 1, 2
  164.  
  165.   
  166. 'Turn on the pull down menu detection for the windows
  167.  
  168.     WindowToPull 1
  169.  
  170. END SUB
  171.  
  172. SUB InvoiceWindow
  173.  
  174. '::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  175. 'Define the colors and edit fields.
  176. '::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  177.  
  178.  
  179.     WindowColors 7, 1, 7, 1, 15, 1, 1, 3
  180.  
  181.     WindowOn 2
  182.                  
  183.     WindowPrint 2, 2, 2, "NAME   : " + RTRIM$(dat.names), 1
  184.    
  185.     EditFieldColors 0, 3
  186.   
  187.     EditFieldDefine 2, 1, RTRIM$(dat.product), 3, 2, 36, 35, "PRODUCT: ", 1
  188.     EditFieldDefine 2, 2, RTRIM$(dat.price), 4, 2, 11, 10, "PRICE $:", 4
  189.  
  190.  
  191.                                       
  192. '===========================================================================
  193. 'Show the mouse, set the cursor in the first field and make the widow active
  194. '===========================================================================
  195.  
  196.     MouseShow
  197.  
  198.     item = 1
  199.  
  200.     DO
  201.   
  202.         IF WhichWindow = 1 THEN EXIT DO
  203.         IF DONEFLAG THEN EXIT DO
  204.  
  205.         IF item > 2 THEN item = 1
  206.         IF item < 1 THEN item = 2
  207.       
  208.         WindowActive item
  209.  
  210.         SELECT CASE WindowEvent(0)              'Find out what took place.
  211.  
  212.             CASE 1                              'A mouse event took place
  213.                SELECT CASE WindowEvent(1)       'Which field was selected
  214.                 
  215.                   CASE 100                      'The mouse was clicked on
  216.                     PullDownActive              'the pull down menu bar
  217.                     MenuControl
  218.  
  219.                   CASE ELSE
  220.                     item = WindowEvent(1)
  221.  
  222.                 END SELECT
  223.  
  224.              CASE 2                             'A key was pressed
  225.                 SELECT CASE WindowEvent(2)      'Which field are we on
  226.  
  227.                     CASE 1, 3, 6                'Enter, Tab, or Down arrow
  228.                         item = item + 1
  229.                   
  230.                     CASE 4                      'Shift Tab or Up arrow
  231.                         item = item - 1
  232.                   
  233.                     CASE 100                    'Alt Key
  234.                         PullDownActive
  235.                         MenuControl
  236.  
  237.                     CASE ELSE
  238.                         BEEP
  239.                                               
  240.                  END SELECT
  241.  
  242.        END SELECT
  243.     LOOP
  244.  
  245.  
  246. '===========================================================================
  247. 'Assign the variables to the type structure, turn off the mouse and close
  248. 'the window.
  249. '===========================================================================
  250.  
  251. GOSUB AssignInvoices
  252.  
  253. MouseHide
  254. WindowOff 2
  255.  
  256. EXIT SUB
  257.  
  258. ':::::::::::::::::::::::::::: Routines
  259.  
  260. AssignInvoices:
  261.  
  262.     dat.product = EditFieldGet(1)
  263.     dat.price = EditFieldGet(2)
  264.                             
  265. RETURN
  266.  
  267. END SUB
  268.  
  269. SUB MenuControl
  270.  
  271. '===========================================================================
  272. '
  273. 'This routine figures program flow depending on the selection from the pull
  274. 'down menu. Notice that there is no loop in this sub. It only determines
  275. 'if a selection was made, then sets the variable switches to reflect it.
  276. '
  277. 'Called from the window loops in NameAddrsWindow and InvoiceWindow.
  278. '
  279. '===========================================================================
  280.  
  281.     menu = PullDownInfo(1)
  282.     item = PullDownInfo(2)
  283.  
  284.     SELECT CASE menu
  285.  
  286.         CASE 1                      'The first menu was chosen.
  287.             SELECT CASE item
  288.                 CASE 1
  289.                     WhichWindow = 1
  290.  
  291.                 CASE 2
  292.                     WhichWindow = 2
  293.  
  294.             END SELECT
  295.           
  296.         CASE 2                      'The second menu was chosen.
  297.             SELECT CASE item
  298.                 CASE 1
  299.                     DONEFLAG = TRUE
  300.  
  301.             END SELECT
  302.  
  303.     END SELECT
  304.  
  305.  
  306. END SUB
  307.  
  308. SUB NameAddrsWindow
  309.  
  310. '::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  311. 'Define the colors and edit fields.
  312. '::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  313.  
  314.     WindowColors 0, 7, 0, 7, 15, 1, 1, 3
  315.  
  316.     WindowOn 1
  317.  
  318.     EditFieldColors 0, 3
  319.    
  320.     EditFieldDefine 1, 1, RTRIM$(dat.names), 2, 3, 36, 35, "NAME   :", 1
  321.     EditFieldDefine 1, 2, RTRIM$(dat.address), 3, 3, 36, 35, "ADDRESS:", 1
  322.     EditFieldDefine 1, 3, RTRIM$(dat.city), 4, 3, 21, 20, "CITY   :", 1
  323.     EditFieldDefine 1, 4, RTRIM$(dat.state), 4, 34, 3, 2, "STATE  :", 20
  324.     EditFieldDefine 1, 5, RTRIM$(dat.zip), 4, 47, 6, 5, "CITY   :", 3
  325.  
  326. '===========================================================================
  327. 'Show the mouse, set the cursor in the first field and make the widow active
  328. '===========================================================================
  329.    
  330.     item = 1
  331.  
  332.     MouseShow
  333.  
  334.     DO
  335.    
  336.         IF WhichWindow = 2 THEN EXIT DO
  337.         IF DONEFLAG THEN EXIT DO
  338.  
  339.         IF item > 5 THEN item = 1
  340.         IF item < 1 THEN item = 5
  341.        
  342.         WindowActive item
  343.  
  344.         SELECT CASE WindowEvent(0)              'Find out what took place.
  345.  
  346.             CASE 1                              'A mouse event took place
  347.                SELECT CASE WindowEvent(1)       'Which field was selected
  348.                  
  349.                   CASE 100                      'The mouse was clicked on
  350.                     PullDownActive              'the pull down menu bar
  351.                     MenuControl
  352.  
  353.                   CASE ELSE
  354.                     item = WindowEvent(1)
  355.  
  356.                 END SELECT
  357.  
  358.              CASE 2                             'A key was pressed
  359.                 SELECT CASE WindowEvent(2)      'Which field are we on
  360.  
  361.                     CASE 1, 3, 6                'Enter, Tab, or Down arrow
  362.                         item = item + 1
  363.                    
  364.                     CASE 4                      'Shift Tab or Up arrow
  365.                         item = item - 1
  366.                    
  367.                     CASE 100                    'Alt Key
  368.                         PullDownActive
  369.                         MenuControl
  370.  
  371.                     CASE ELSE
  372.                         BEEP
  373.                                                
  374.                  END SELECT
  375.  
  376.        END SELECT
  377.     LOOP
  378.  
  379. '===========================================================================
  380. 'Assign the variables to the type structure, turn off the mouse and close
  381. 'the window.
  382. '===========================================================================
  383.  
  384. GOSUB AssignData
  385.  
  386. MouseHide
  387. WindowOff 1
  388.  
  389. EXIT SUB
  390.  
  391. ':::::::::::::::::::::::::::: Routines
  392.  
  393. AssignData:
  394.  
  395.     dat.names = EditFieldGet(1)
  396.     dat.address = EditFieldGet(2)
  397.     dat.city = EditFieldGet(3)
  398.     dat.state = EditFieldGet(4)
  399.     dat.zip = EditFieldGet(5)
  400.                           
  401. RETURN
  402.  
  403. END SUB
  404.  
  405. SUB WindowControl
  406.  
  407. '::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  408. '
  409. 'This SUB controls the program flow (which window to go to). By using this
  410. 'format of program control, the stack space is kept as clean as possible
  411. 'giving you the most memory for your procedure calls.
  412. '
  413. '::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  414.  
  415.         DONEFLAG = FLASE
  416.  
  417.         DO
  418.  
  419.             SELECT CASE WhichWindow
  420.  
  421.                 CASE 1
  422.                     CALL NameAddrsWindow
  423.  
  424.                 CASE 2
  425.                     CALL InvoiceWindow
  426.  
  427.                 CASE ELSE
  428.                     WhichWindow = 1
  429.  
  430.             END SELECT
  431.                        
  432.         LOOP WHILE NOT DONEFLAG
  433.  
  434. END SUB
  435.  
  436.